var Fly = require("flyio/dist/npm/wx")
var fly = new Fly
fly.config.baseURL = "http://wanandroid.com/"

function request(url, method, params) {
  return new Promise((resolve, reject) => {
    fly.request(url, params, {
      method: method
    }).then(response => {
      resolve(response.data)
    }).catch(error => {
      reject(error)
    })
  })
}

export default {
  get(url, params) {
    return this.request(url, "GET", params)
  },
  post(url, params) {
    return this.request(url, "POST", params)
  },
  request(url, method, params) {
    return new Promise((resolve, reject) => {
      fly.request(url, params, {
        method: method
      }).then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
